//
//  FTBundle.m
//  FTBundle
//
//  Created by JackieYip on 2017/5/24.
//  Copyright © 2017年 mondial-d. All rights reserved.
//

#import "FTBundle.h"
#import "NSBundle+FTLanguage.h"

@interface FTBundle ()
@property (strong, nonatomic, readwrite) NSBundle *bundle;

@end

@implementation FTBundle

+ (instancetype)sharedInstance
{
    static FTBundle *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[FTBundle alloc] init];
    });
    return sharedInstance;
}

- (void)setupWithLanguageLocaleIdentifier:(NSString *)languageLocaleIdentifier
{
    // app支持的语言bundle
    //    __block NSString *appCurrentBundleString = nil;
    //    [self.appSupportLanguages enumerateObjectsUsingBlock:^(id  _Nonnull appLanguage, NSUInteger idx, BOOL * _Nonnull stop) {
    //        if ([self.languageLocale.localeIdentifier hasPrefix:appLanguage])
    //            appCurrentBundleString = appLanguage;
    //    }];
    //    if (!appCurrentBundleString)
    //        // 找不到支持的语言包，则使用默认语言包：中文
    //        appCurrentBundleString = @"zh-Hans";
    [NSBundle setLanguage:languageLocaleIdentifier];
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:languageLocaleIdentifier ofType:@"lproj"];
    self.bundle = [NSBundle bundleWithPath:bundlePath];
}

#pragma mark - getter
- (NSBundle *)bundle {
    if (!_bundle) {
        self.bundle = [NSBundle mainBundle];
    }
    return _bundle;
}
@end
